﻿using Codeplex.Data;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Net;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace nanobot {
    public partial class Withdrawal_Form : Form {
        List<string> Currencies;
        public Withdrawal_Form () {
            getCurrencies();
            InitializeComponent();

        }

        private void getCurrencies () {

            using ( WebClient client = new WebClient() ) {
                client.DownloadStringCompleted += client_DownloadStringCompleted;
                client.DownloadStringAsync( new Uri( "https://poloniex.com/public?command=returnCurrencies" ) );

            }


        }

        private void client_DownloadStringCompleted ( object sender, DownloadStringCompletedEventArgs e ) {
            dynamic [] json = ( dynamic[] ) DynamicJson.Parse( e.Result );
            Currencies = new List<string>();

            foreach ( var item in json ) {
                if ( item.Key == "item" ) {
                    Currencies.Add( "1CR" );

                } else {
                    Currencies.Add( item.Key );

                }

            }

            comboBox.DataSource = Currencies.ToArray();
            button2.Enabled = true;

        }


        private void ChangeEnablePropertyForControl_ThreadSafe ( Control varControl, bool b ) {
            if ( varControl.InvokeRequired ) {
                varControl.Invoke(
                    new Action<Control, bool>( ChangeEnablePropertyForControl_ThreadSafe ),
                    new object[] { varControl, b }
                    );
            } else {
                varControl.Enabled = b;
            }


        }

        private void comboBox_SelectedIndexChanged ( object sender, EventArgs e ) {
            string c = ( string ) comboBox.SelectedItem;
            if ( c == "XMR" ) {
                label4.Enabled = true;
                txtPaymentID.Enabled = true;
            } else {
                label4.Enabled = false;
                txtPaymentID.Enabled = false;
            }

        }


    }
}
